<template>
  <div>
    <div>
      <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="100px">
        <el-form-item label="执行账户" prop="field102">
          <el-radio-group v-model="formData.field102" size="medium">
            <el-radio v-for="(item, index) in field102Options" :key="index" :label="item.value"
                      :disabled="item.disabled">{{ item.label }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item size="large">
          <el-button type="primary" @click="loadMxcKlineOrders">加载订单</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table v-if="klineOrders.length>0"
              :data="klineOrders"
              height="700"
              border
              style="width: 100%">
      <el-table-column
        label="订单号"
        prop="id"
        sortable
      >
      </el-table-column>
      <el-table-column
        label="日期"
        prop="createTime"
        sortable
      >
        <template slot-scope="scope">{{ scope.row.createTime| dfmt }}</template>
      </el-table-column>
      <el-table-column
        prop="price"
        label="价格"
        sortable
      >
      </el-table-column>
      <el-table-column
        prop="quantity"
        label="数量"
        sortable
      >
      </el-table-column>
      <el-table-column
        prop="dealQuantity"
        label="已成交"
        sortable
      >
      </el-table-column>
      <el-table-column
        prop="dealType"
        sortable
        label="类型"
      >
        <template slot-scope="scope">
          {{ scope.row.dealType == 'BID' ? '买单' : '卖单' }}
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
      >
        <template slot-scope="scope">
          <el-button @click="cancelOrder(scope.row)" type="text" size="small">撤销</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>

import {
  getFlyOrder,
  cancelOrder,
} from "@/api/platform/running";

export default {
  components: {},
  props: {
    platform: null,
    runningId: null,
  },
  data() {
    return {
      klineOrders: [],
      formData: {
        field102: 1,
      },
      rules: {
        field102: [{
          required: true,
          message: '执行账户不能为空',
          trigger: 'change'
        }],
      },
      field102Options: [{
        "label": "深度账户",
        "value": 1
      }, {
        "label": "K线账户",
        "value": 2
      }],
    }
  },
  computed: {},
  watch: {},
  created() {
  },
  mounted() {
    this.loadMxcKlineOrders()
  },
  methods: {
    loadMxcKlineOrders() {
      getFlyOrder(this.runningId, {platform: this.platform, type: this.formData.field102}).then(res => {
        this.klineOrders = res.data;
      })
    },
    cancelOrder(row) {
      cancelOrder(this.runningId, {orderId: row.id, platform: this.platform, type: this.formData.field102}).then(res => {
        this.loadMxcKlineOrders()
      })
    },
  }
}

</script>
<style>
</style>
